﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;


namespace QLyHocSinhTHPT
{
    public partial class frmDangNhap : DevComponents.DotNetBar.Office2007Form
    {
        public frmDangNhap()
        {
            InitializeComponent();
        }

        public SqlConnection GetConnect()
        {
           return new SqlConnection( @"Data Source=HOANGNGOC-PC\HOANGNGOC;Initial Catalog=QLyHocSinhTHPT;Integrated Security=True");
        }

        public DataTable KTDangNhap(string ten, string pass)
        {
            string sql = "Select * from Dangnhap where Ten ='" + ten + "'and Matkhau ='" + pass + "'";
            SqlConnection con = GetConnect();
            SqlCommand cmd = new SqlCommand(sql, con);
            SqlDataAdapter adap = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            adap.Fill(dt);
            return dt;
        }

        private void btnlongin_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt = KTDangNhap(txttendangnhap.Text, txtmatkhau.Text);
            if (dt.Rows.Count > 0)
            {
                this.Hide();
                Form1 frmMain = new Form1();
                frmMain.ShowDialog();
                this.Close();
            }
            else
            {
                lblloi.Text = "Đăng nhập không thành công !";
            }
        }

        private void btnthoat_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void frmDangNhap_Load(object sender, EventArgs e)
        {
            txttendangnhap.Focus();
        }

    }
}
